using System.Linq;
using Magiq.Tests.TestModel;
using NUnit.Framework;

namespace Magiq.Tests {
  public abstract class BaseMagiqProviderTest {
    protected IMagiqTestConfigurator Configurator { get; private set; }

    protected IQueryable<TestClass1> TestClass1s { get; private set; }
    protected IQueryable<TestClass2> TestClass2s { get; private set; }
    protected IQueryable<TestClass3> TestClass3s { get; private set; }
    protected abstract IMagiqTestConfigurator GetConfigurator();

    private void InitModel()
    {
        var domain = new TestDomain();

        TestClass2s = Configurator.PersistAndGet(domain.Class2s);
        TestClass1s = Configurator.PersistAndGet(domain.Class1s);
        TestClass3s = Configurator.GetQueryable<TestClass3>();
    }

      [TestFixtureSetUp]
    public void FixtureSetUp() {
      Configurator = GetConfigurator();
    }

    [SetUp]
    public void SetUp() {
      Configurator.SetUp();
      InitModel();
      Initialize();
    }

    [TearDown]
    public void TearDown() {
      Configurator.TearDown();
    }

    protected virtual void Initialize() {}
  }
}